package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckitemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckitemServiceImpl implements CheckitemService {
    @Autowired
    private CheckitemMapper checkitemMapper;
    /*
     * 新增检查项
     * */

    public void add(CheckItem checkItem) {
        //向数据库中新增检查项
        checkitemMapper.add(checkItem);
    }

    /*
     * 根据id删除检查项
     * */
    @Override
    public void delete(Integer id) {

        checkitemMapper.delete(id);
    }

    //分页条件查找

    @Override
    public PageResult findPage(QueryPageBean queryPage) {

        //设置分页条件
        PageHelper.startPage(queryPage.getCurrentPage(), queryPage.getPageSize());

        List<CheckItem> page = checkitemMapper.findPage(queryPage);

        Page<CheckItem> p = (Page<CheckItem>) page;

        return new PageResult(p.getTotal(), p.getResult());
    }

    //查询所有检查项

    @Override
    public List<CheckItem> findAll() {
        return checkitemMapper.findAll();
    }

    //根据id查询检查项

    @Override
    public CheckItem findById(Integer id) {
        return checkitemMapper.findById(id);
    }

    //编辑检查项

    @Override
    public void edit(CheckItem checkItem) {
        checkitemMapper.edit(checkItem);
    }
}
